package com.jinbaoty.recyclebins.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.view.Gravity;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.jinbaoty.recyclebins.utils.ToastUtil;
import com.kongzue.dialog.v3.TipDialog;
import com.sdsmdg.tastytoast.TastyToast;
import com.xuexiang.xui.widget.dialog.DialogLoader;

import java.security.DigestInputStream;

import okio.HashingSource;
import okio.Source;

public class BaseActivity extends AppCompatActivity {

    public SharedPreferences getAppConfig(){
        SharedPreferences deviceInfoPreference = this.getSharedPreferences("device_info", Context.MODE_PRIVATE);
        return deviceInfoPreference;
    }
    public boolean isAdmin(String pwd){
        SharedPreferences appConfig = getAppConfig();
        String adminPwd = appConfig.getString("adminPwd", "");
        return false;
    }
    protected void showToast(String s) {
        //TastyToast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT,TastyToast.INFO).show();
        showToastCenter(s,3);
    }
    protected void showLongToast(String s) {
        //Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
        showToastCenter(s,5);
    }
    protected Dialog alert(String msg){
        return alert("提示",msg);
    }
    protected Dialog alert(String title,String msg){
        Dialog alertDialog = DialogLoader.getInstance().showTipDialog(this, title, msg, "确定");
        alertDialog.show();
        return alertDialog;
    }
    protected  void showTip(String msg){
        /*Toast toast = TastyToast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG, TastyToast.SUCCESS);
        toast.setGravity(Gravity.CENTER,0,0);
        toast.show();*/
        TipDialog.show(this,msg, TipDialog.TYPE.WARNING).setTipTime(10*1000).setCancelable(true);
    }
    protected  void showToastCenter(String msg,int seconds){
        showToastCenter(msg,seconds,20);
    }

    protected void showToastCenter(String msg,int seconds,float textSize){
        /*final Toast toast = TastyToast.makeText(getApplicationContext(), msg,Toast.LENGTH_LONG, TastyToast.SUCCESS);



        toast.setGravity(Gravity.CENTER,0,0);
        View view = toast.getView();
        TextView viewById = (TextView)view.findViewById(R.id.toastMessage);
        viewById.setTextSize(textSize);
        //toast.setDuration(10*1000);
        final Timer showToastTimer = new Timer();
        showToastTimer.schedule(new TimerTask(){

            @Override
            public void run() {
                toast.show();
            }
        },0,2*1000);
        Timer closeToastTimer = new Timer();
        closeToastTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                showToastTimer.cancel();
                toast.cancel();
            }
        },seconds*1000);*/
        final ToastUtil toast = new ToastUtil(getApplicationContext(),TastyToast.SUCCESS,msg);
        toast.show(seconds*1000);
    }
}

